package top.jsjkxyjs.blackbox.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.jsjkxyjs.blackbox.entity.Car;
import top.jsjkxyjs.blackbox.entity.User;
import top.jsjkxyjs.blackbox.mapper.CarMapper;
import top.jsjkxyjs.blackbox.service.CarService;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {
	@Autowired
	CarMapper carMapper;


	@Override
	public boolean checkLicensePlate(User user, Car car) {
		List<Car> userAllCars = carMapper.getAllCarsByUserId(user.getId());
		for (Car tmpCar : userAllCars) {
			if (tmpCar.getLicensePlate().equals(car.getLicensePlate())) {
				return false;
			}
		}
		return true;
	}

	@Override
	public int getAllCars() {
		List<Car> cars = carMapper.selectList(null);
		return cars.size();
	}

	@Override
	public List<Car> getUserAllCars(User user) {
		List<Car> userAllCars = carMapper.getAllCarsByUserId(user.getId());
		return userAllCars;
	}
}
